package Exception_0209;

import java.util.Scanner;

public class Login {
    String name = "1";
    String password = "123456";
    public void loginInfO(String name,String password) throws NameException, PasswordException{
        if(!this.name.equals(name)){
            throw new NameException("用户名错误");
        }
        if(!this.password.equals(password)){
            throw new PasswordException("密码错误");
        }
    }

    public static void main(String[] args) {
        Login login = new Login();
        Scanner scanner = new Scanner(System.in);
        try{
            login.loginInfO("0","123456");
        }catch (NameException e){
            e.printStackTrace();
            System.out.println("请再次输入姓名：");
            String name = scanner.nextLine();
            login.loginInfO(name,"123456");
        }catch (PasswordException e){
            e.printStackTrace();
        }finally{
            scanner.close();
        }
    }
}
